﻿// -----------------------------------------------------------------------
// <copyright file="DonThuocServices.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ASS.BUS.Services
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ASS.DAO;
    using ASS.BUS.DTO;
    using System.Windows.Forms;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class DonThuocServices
    {
        public bool Add(DonThuoc donThuoc)
        {
            bool addSuccsess = false;
            using (var db = new DataContext())
            {
                try
                {
                    db.DonThuocs.Add(donThuoc);
                    db.SaveChanges();
                    addSuccsess = true;
                }
                catch (Exception ex)
                {
                    addSuccsess = false;
                    MessageBox.Show(ex.Message);
                }
            }
            return addSuccsess;
        }

        public DonThuoc GetDonThuoc(int id)
        {
            using (var db = new DataContext())
            {
                var item = db.DonThuocs.SingleOrDefault(x => x.MaToa == id);
                return item;

            }
        }


        public List<DonThuoc> GetDonThuocs()
        {
            using (var db = new DataContext())
            {
                var items = db.DonThuocs.ToList();

                return items;
            }
        }

        public bool Delete (int id)
        {
            using (var db = new DataContext())
            {
                var items = db.DonThuocs.FirstOrDefault(x => x.MaToa == id);
                if (items == null)
                {
                    return false;
                }
              
                {
                    db.DonThuocs.Remove(items);
                    db.SaveChanges();
                    return true;
                }
                 
            }
        }
    }
}
